/*把一个dom组件(html,css)封装jquery插件，我们以后只需要调用这个函数，就可以使用了*/
!(function($, fi) {
  var lunbotu = function(element, options) {
    var data = options.data;
    var jStepGraph = $(this);
    this.el = element;
    this.size = data.length;
    this.index = 0;
    this.el.addClass("main");
    for (var i = 0; i < data.length; i++) {
      var htmlString =
        '<div class="main-box"><img>' + data[i].url + "</img></div>";
      var jStep = $(htmlString);
      this.el.append(jStep);
    }
  };

  lunbotu.prototype.next = function() {
    if (this.index < this.size) {
      this.el.find(".main-box").eq(this.index).addClass("left");
      this.index++;
      //   console.log( this)
    }
  };

  lunbotu.prototype.pri = function() {
    if (this.index > 0) {
      this.index--;
      this.el.find(".step").eq(this.index).removeClass("active");
    }
  };

  var plugin = function(option) {
    return this.each(function() {
      var jThis = $(this);
      var options = $.extend(
        {},
        jThis.data(),
        typeof option == "object" ? option : false
      );
      var data = jThis.data("step-graph");

      if (!data) {
        jThis.data("step-graph", new lunbotu(jThis, options));
      }
      if (typeof option == "string") {
        
        data[option].call(data);
      }
    });
  };

  $.fn.lunbotu = plugin;
})(window.$, window.fi);
